package com.dr.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dr.pojo.User;
import com.dr.service.LoginService;

@Controller
public class LoginController {
	@Autowired
	private LoginService service;
	
	@RequestMapping("/login")
	public String login(User user, HttpSession session,Model model) {
		System.out.println("------------------------------------------------------------");
		System.out.println(user);
		User loginUser = service.findUser(user);
		System.out.println(loginUser);
		if(loginUser==null) {
			//登录失败
			model.addAttribute("loginErrMsg", "用户名或密码错误，请重新输入！");
			return "/login.html";
			//return "forward:/index.html";第二种方法
		}
		else {
			session.setAttribute("loginUser",loginUser);//登录用户记录Session,然后传向main.html
			return "/main.html";
		}
	}

}
